home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / ttedit / mdi_stuf.bas < prev    next >
BASIC Source File  |  1995-01-10  |  2KB  |  93 lines

  1. Option Explicit
  2. '
  3. ' This module contains the routines to track the instances
  4. ' of each type of form.
  5. '
  6.  
  7.  
  8. Type NextForm_Type
  9.      Formclass  As Integer
  10.      Index As Integer
  11.      Tag As String
  12. End Type
  13.  
  14. Type FormDetailsType
  15.      Index As Integer
  16.      Formclass As Integer
  17.      Deleted As Integer
  18. End Type
  19.  
  20. Dim FormDetails() As FormDetailsType
  21.  
  22. Function Countforms (Class As Integer) As Integer
  23.    Dim X As Integer
  24.    Dim Count As Integer
  25.    For X = 0 To Forms.Count - 1
  26.      If Len(Forms(X).Tag) = 6 Then
  27.     If Val(Right(Forms(X).Tag, 3)) = Class Then Count = Count + 1
  28.      End If
  29.    Next
  30.    Countforms = Count
  31. End Function
  32.  
  33. Sub DeleteForm (F As Form)
  34.   Dim X As Integer
  35.   For X = 0 To UBound(FormDetails)
  36.     If FormDetails(X).Formclass = GetFormClass(F) Then
  37.        If FormDetails(X).Index = GetFormIndex(F) Then
  38.       FormDetails(X).Deleted = True
  39.       Exit For
  40.        End If
  41.      End If
  42.    Next
  43. End Sub
  44.  
  45. Function GetFormClass (F As Form) As Integer
  46.     If Len(Trim(F.Tag)) = 6 Then GetFormClass = Val(Right(F.Tag, 3))
  47. End Function
  48.  
  49. Function GetFormIndex (F As Form) As Integer
  50.     If Len(Trim(F.Tag)) = 6 Then GetFormIndex = Val(Left(F.Tag, 3))
  51. End Function
  52.  
  53. Sub Init_FormDetails ()
  54.    ReDim FormDetails(0)
  55. End Sub
  56.  
  57. Sub Nextform (F() As Form, NF As NextForm_Type)
  58.     Dim I As Integer, X  As Integer
  59.     Dim ArrayCount As Integer
  60.  
  61.     ArrayCount = UBound(FormDetails)
  62.     ' Cycle throught the document array. If one of the
  63.     ' documents has been deleted, then return that
  64.     ' index.
  65.     For I = 1 To ArrayCount
  66.      If FormDetails(I).Formclass = NF.Formclass Then
  67.       If FormDetails(I).Deleted Then
  68.     NF.Index = I
  69.     NF.Tag = Format$(I, "000") & Format$(NF.Formclass, "000")
  70.     FormDetails(I).Deleted = False
  71.     FormDetails(I).Formclass = NF.Formclass
  72.     Exit Sub
  73.       End If
  74.      End If
  75.     Next
  76.  
  77.     ' If none of the elements in the document array have
  78.     ' been deleted, then increment the document and the
  79.     ' state arrays by one and return the index to the
  80.     ' new element.
  81.     ReDim Preserve FormDetails(ArrayCount + 1)
  82.     For I = 1 To ArrayCount
  83.        If FormDetails(I).Formclass = NF.Formclass Then X = X + 1
  84.     Next
  85.     X = X + 1
  86.     ReDim Preserve F(X)
  87.     FormDetails(I).Formclass = NF.Formclass
  88.     FormDetails(I).Index = X
  89.     NF.Index = X
  90.     NF.Tag = Format$(I, "000") & Format$(NF.Formclass, "000")
  91. End Sub
  92.  
  93.